package pack1;

import java.util.Arrays;

public class InsertSort {
    public static void main(String[] args) {
        int[]arr={3,5,6,88,99,2,1,5};
        int[]arr2={9,8,7,6,5,4,3,2,1};
        insertSort(arr2);
        System.out.println(Arrays.toString(arr2));
    }


    public static void insertSort(int[]arr){
        for (int i = 1; i < arr.length; i++) {
            int temp=arr[i];
            int j;
            for ( j =i-1 ; j >=0; j--) {
                if(arr[j]>temp){
                    arr[j+1]=arr[j];
                }else{
                    arr[j+1]=temp;
                    break;
                }
            }
            arr[j+1]=temp;
        }
    }
}
